<?php
require_once("header.php");
require_once("check.php");
require_once("../system/conndb.php");
$link = connect();
//判断输入框里是否有内容
if(isset($_POST["videoname"]))
	$sql="select t1.*,t2.typename from 
   videos t1 left join videotype t2 
   on t1.tid = t2.tid where videoname like '%"
			.$_POST['videoname']."%'";
else 
	$sql = "select t1.*,t2.typename from 
   videos t1 left join videotype t2 
   on t1.tid = t2.tid";
$result = mysqli_query($link,$sql);
//$num = mysqli_num_rows($result);
//if($num>0) 
$data = mysqli_fetch_all($result,MYSQLI_ASSOC);
//var_dump($data);

?>

    <main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-4">
      <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
        <h1 class="h2">视频管理</h1>
        <div class="btn-toolbar mb-2 mb-md-0">
          <div class="btn-group mr-2">
            <button type="button" class="btn btn-sm btn-outline-secondary">Share</button>
            <button type="button" class="btn btn-sm btn-outline-secondary">Export</button>
          </div>
          <button type="button" class="btn btn-sm btn-outline-secondary dropdown-toggle">
            <span data-feather="calendar"></span>
            This week
          </button>
        </div>
      </div>

      
      <h2>视频列表</h2>
	   <form action="videolist.php" method="post">
		<input name="videoname" type="text"/>
		<input type="submit" value="搜索" />
	  
	  </form>
	  <a href="videoadd.php" class="btn btn-primary">添加视频</a>
	  <table class="table">
		  <thead>
			<tr>
			  <th scope="col">#</th>
			  <th scope="col">名称</th>
			  <th scope="col">简介</th>
			  <th scope="col">类型</th>
			  <th scope="col">缩略图</th>
			 <th scope="col">操作</th>
			</tr>
		  </thead>
		  <tbody>
		  <?php
			if(count($data)==0)
				echo '<tr><td colspan="5">暂无数据</td></tr>';
			else{
				foreach($data as $index=>$one){
					echo '<tr scope="row">';
					echo '<td>'.($index+1).'</td>';
					echo '<td>'.$one['videoname'].'</td>';
					echo '<td>'.$one['intro'].'</td>';
					echo '<td>'.$one['typename'].'</td>';
					echo '<td><img src="../uploads/poster/'.$one['pic']
							.'" width=60/></td>';
					echo '<td>';
					echo '<a href="videoedit.php?vid='
						.$one['vid'].'">修改</a>&nbsp;&nbsp;';	
					echo '<a href="vdetail.php?vid='
						.$one['vid'].'">详情</a>&nbsp;&nbsp;';
					
					echo '<a href="vdel.php?vid='
						.$one['vid'].
						'" onClick="return confirm(\'确定要删除?\')" >删除</a>';
					
					echo '</td>';
					echo '</tr>';
				}
				
			}
			?>

		  </tbody>
	 </table> 
      
    </main>
   <?php 
  require_once("footer.php");
  ?>